<template>

    <div class="my">

        <div class="mian1">
            <div class="imgbox">
                <div class="imgblack"></div>
            </div>
            <div class="container">
                <div class="userbox">
                    <div class="boxtop">
                        <div class="userhead">
                            <div class="imgbox">
                                <img src="../assets/img/myimg.jpg" alt="" class="auto-img">
                            </div>
                        </div>
                        <div class="usercont">
                            <div class="top1">
                                <h2 style="color: #fff;">PIG</h2>
                                <ul>
                                    <li class="icon"><img src="../assets/img/China.svg" alt="" class="auto-img"></li>
                                    <!-- <li class="icon"><img src="../assets/img/pen.svg" alt="" class="auto-img"></li>
                                    <li class="icon"><img src="../assets/img/book.svg" alt="" class="auto-img"></li> -->
                                </ul>
                                
                            </div>
                            <div class="boxbtm">
                                <ul class="uesrdata">
                                    <li>
                                        <div class="num">1</div>
                                        <div class="numname">声望</div>
                                    </li>
                                    <li>
                                        <div class="num">0</div>
                                        <div class="numname">粉丝</div>
                                    </li>
                                    <li>
                                        <div class="num">{{followdata.length==0?0:followdata.length}}</div>
                                        <div class="numname">关注</div>
                                    </li>
                                    <li>
                                        <div class="num">0</div>
                                        <div class="numname">被赞</div>
                                    </li>
                                    
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="qianm" style="margin-top: 24px; font-size: 14px;color: #838385;" >
                        
                    </div>
                </div>
            </div>
        </div>
        <div class="contentnav">
            <div class="container">
                <div class="warp1">
                    <div class="navbox">
                        <div class="title" v-show="all==0">
                            <h3>全部作品</h3>
                            <span>0</span>
                        </div>
                        <div class="title" v-show="all==1">
                            <h3>我的收藏</h3>
                            <!-- 如果没有内容则为0 -->
                            <span>{{Collect.length==0?0:Collect.length}}</span>
                        </div>
                        <div class="title" v-show="all==2">
                            <h3>我的关注</h3>
                            <span>{{followdata.length==0?0:followdata.length}}</span>
                        </div>
                        <!-- <div class="iconbox">
                            <div class="iconlit">
                                <div class="icon">
                                    <img src="../assets/img/top1.svg" alt="" class="auto-img">
                                </div>
                                <span>1</span>
                            </div>
                            <div class="iconlit">
                                <div class="icon">
                                    <img src="../assets/img/top2.svg" alt="" class="auto-img">
                                </div>
                                
                                <span>1</span>
                            </div>
                            <div class="iconlit">
                                <div class="icon">
                                    <img src="../assets/img/top3.svg" alt="" class="auto-img">
                                </div>
                                <span>1</span>
                            </div>
                            <div class="iconlit">
                                <div class="icon">
                                    <img src="../assets/img/jingxuan.svg" alt="" class="auto-img">
                                </div>
                                <span>17</span>
                            </div>
                        </div> -->
                    </div>
                    <div class="allbox">
                        <div class="all" style="font-size: 14px;">
                            <!-- <p v-show="all==0">全部</p>  -->
                            <p v-show="all==1">我的收藏</p>
                            <p v-show="all==2">我的关注</p>
                        <div class="icon">
                            <img src="../assets/img/under.png" alt="" class="auto-img">
                        </div>
                        <div class="box">
                            <div class="choice" ref="choice">
                                <!-- <div @click="allshow" :class="{'con':all==0}">全部</div> -->
                                <div @click="collectshow" :class="{'con':all==1}">我的收藏</div>
                                <div @click="followshow" :class="{'con':all==2}">我的关注</div>
                            </div>
                        </div>
                        
                    </div>
                    </div>
                    
                </div>
                
            </div>
        </div>
        <!-- <div class="main" v-show="all==0">
            <div class="container">
                <div class="box">
                    <div class="content">
                        <div class="imgbox">
                            <img src="../assets/img/ia_600000123.jpg" alt="">                    
                        </div>
                        <div class="boxmain">
                           <div class="user">
                            <p>Osmo Action 3 - 总想要透过你的眼睛</p>
                            <div class="usermain">
                                <div class="useimg">
                                    <div class="headimg">
                                        <img class="auto-img" src="../assets/img/ia_300000345.jpg" alt="">
                                    </div>
                                    <p style="margin-left:10px;">朱翠胜</p>
                                </div>
                                <div class="state">
                                    <div class="icon">
                                        <img src="../assets/img/goodw.png" alt="" class="auto-img">
                                    </div>
                                    <p>54</p>
                                    <div class="icon">
                                        <img src="../assets/img/news.png" alt="" class="auto-img">
                                    </div>
                                    <p>0</p>
                                </div>
                            </div>
                        </div> 
                        </div>
                        
                    </div>
                </div>
            </div>
        </div> -->
        <!-- 我的收藏 -->
        <div class="main" v-show="all==1">
            <div class="container">
                <div class="mainbox" v-if="Collect.length!=0">
                    <div class="box" @click="todetails(item.slug)" v-for="item in Collect" :key="item.slug">
                    <div class="content">
                        <div class="imgbox">
                            <img :src="item.image.large" alt="">                    
                        </div>
                        <div class="boxmain">
                           <div class="user">
                            <p>{{item.title}}</p>
                            <div class="usermain">
                                <div class="useimg">
                                    <div class="headimg">
                                        <img class="auto-img" :src="item.user.avatar.large" alt="">
                                    </div>
                                    <p style="margin-left:10px;">{{item.user.name}}</p>
                                </div>
                                <div class="state">
                                    <div class="icon">
                                        <img src="../assets/img/goodw.png" alt="" class="auto-img">
                                    </div>
                                    <p>{{item.like_count}}</p>
                                    <div class="icon">
                                        <img src="../assets/img/news.png" alt="" class="auto-img">
                                    </div>
                                    <p>{{Comment.length}}</p>
                                </div>
                            </div>
                        </div> 
                        </div>
                        
                    </div>
                    
                  
                    
                    </div>
                    <div class="nullbox"></div>
                </div>
                <el-empty v-if="Collect.length==0" description="暂无内容哦~"></el-empty>
            </div>
        </div>
        <!-- 我的关注 -->
        <div class="follow" v-show="all==2">
            <div class="container">
                <div class="boxmain" >
                    <div class="box" v-for="item in followdata" :key="item.slug">
                    <div class="content" >
                        <div class="userimg" @click="user(item.user.slug)">
                            <img :src="item.user.avatar.large" alt="" class="auto-img">
                        </div>
                        <div class="userinfo" @click="user(item.user.slug)">
                            <div class="name">{{item.user.name}}</div>
                            <div class="icon">
                                <img src="../assets/img/China.svg" alt="" class="auto-img">
                            </div>
                            <div class="icon">
                                <img src="../assets/img/pen.svg" alt="" class="auto-img">
                            </div>
                            <div class="icon">
                                <img src="../assets/img/V.svg" alt="" class="auto-img">
                            </div>
                            <div class="icon">
                                <img src="../assets/img/book.svg" alt="" class="auto-img">
                            </div>
                        </div>
                        <div class="boxbtm">
                                <ul class="uesrdata">
                                    <li>
                                        <div class="num">1613</div>
                                        <div class="numname">声望</div>
                                    </li>
                                    <li>
                                        <div class="num">1</div>
                                        <div class="numname">粉丝</div>
                                    </li>
                                    <li>
                                        <div class="num">0</div>
                                        <div class="numname">关注</div>
                                    </li>
                                    <li>
                                        <div class="num">0</div>
                                        <div class="numname">被赞</div>
                                    </li>
                                    
                                </ul>
                        </div>
                        <div class="btnboxm" >
                            <div class="btn con" @click="del(item.user.slug)">
                                已关注
                            </div>
                        </div>
                    </div>
                    
                  
                    
                    </div>
                </div>
                <el-empty v-if="followdata.length==0" description="暂无内容哦~"></el-empty>
                
               
   
  
            </div>
        </div>
        
        
        <foot-navbar></foot-navbar>
    </div>
        
</template>

<script>

import FootNavbar from '@/components/FootNavbar.vue'
import { getComment } from '../api/comment' 
    export default {
  components: {  FootNavbar },
        data() {
            return {
                loading: true,
                all:1,
                Collect:[],//收藏数据
                Comment:[],//评论数据
                followdata:[],//关注数据
                Lists:[],//总数据
                
            };
        },
        methods:{
            // 取消关注
            del(id){

                this.Lists.forEach(item => {
                    if (item.user.slug == id) {
                        // 将id用户所有图文详情页的关注状态改变
                        item.care=false;
                        item.favorite_count-=1;
                    }
                });
                let index = this.followdata.findIndex(item=>item.user.slug==id);
                this.followdata.splice(index,1);
                window.localStorage.setItem("followdata",JSON.stringify([this.followdata]))
                window.localStorage.setItem("Listsnew",JSON.stringify([this.Lists]))
            },
            // 跳转到作者个人中心
            user(id){
                console.log(id);
                this.$router.push("/user?id="+ id +"");
            },
            // 全部
            // allshow(){
            //     this.all=0;
            //     this.$refs.choice.style.left=(-28+"px");
            // },
            // 我的收藏
            collectshow(){
                this.all=1;
                // this.$refs.choice.style.left=(0+"px");
            },
            // 我的关注
            followshow(){
                this.all=2;
                // this.$refs.choice.style.left=(0+"px");   
            },
            // 数据替换
            DataFun(){
                // 收藏数据替换
                if(window.localStorage.getItem("Collect")){
                    this.Collect=JSON.parse(window.localStorage.getItem("Collect"))[0];
                }
                if(window.localStorage.getItem("followdata")){
                    this.followdata=JSON.parse(window.localStorage.getItem("followdata"))[0];
                }
                if(window.localStorage.getItem("Listsnew")){
                    this.Lists=JSON.parse(window.localStorage.getItem("Listsnew"))[0];
                }
                // 用户id
                // let id = this.$route.query.id;
                // 获取当前id用户下发布的所有图文数据
                // this.Lists.forEach(item => {
                //     if (item.user.slug == id) {
                //         // 被赞总数
                //         this.good+=item.like_count;
                //     }
                // });
                console.log(this.followdata);
                console.log(this.Lists);
            },
            // 跳转到详情页
            todetails(id){
                this.$router.push("/details?id="+ id +"");
            },
            // 接收评论数据
            getCommentFun(){
                getComment().then(data=>{
                    this.Comment=data.data.items;
                    // 更新数据
                    if(window.localStorage.getItem("Comment")){
                        this.Comment=JSON.parse(window.localStorage.getItem("Comment"))[0];
                    }
                })
            }
        },
        
        created(){
            this.DataFun();
            this.getCommentFun();
            this.$emit("login_local");
        },
        mounted(){
            setTimeout(() => { 
            this.loading=false
            },1000)
        }
    }
</script>

<style lang="scss" scoped>
.my{
    
     .mian1 {
    position: relative;
    & > .imgbox {
      height: 320px;
      background: url(../assets/img/userbackground.jpg) no-repeat;
      background-size: cover;
      background-position: 50%;
      margin-bottom: 144px;
    }
    .imgblack {
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
      background-color: rgba(0,0,0,.4);
    }
  }
  .userbox {
    position: absolute;
    height: 160px;
    bottom: -105px;
  }
  .boxtop {
    display: flex;
    .userhead {
      margin-right: 24px;
      .imgbox {
        width: 120px;
        height: 120px;
        overflow: hidden;
        border-radius: 50%;
        border: 2px solid #fff;
      }
    }
    .usercont {
      .top1 {
        display: flex;
        align-items: center;
        .icon {
          width: 24px;
          height: 24px;
          margin: 0 5px;
        }
      }
    }
  }
  .usercont {
    display: flex;
    flex-direction: column;
    justify-content: center;
    .top1 {
      ul {
        display: flex;
        align-items: center;
        margin-right: 43px;
      }
      .liking {
        width: 64px;
        height: 32px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #1088f2;
        border-radius: 5px;
        margin-right: 16px;
        font-size: 14px;
        color: #fff;
      }
      .skinny {
        width: 45px;
        padding: 0 20px;
        height: 32px;
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: #fff;
        border-radius: 5px;
        .icon {
          width: 16px;
          height: 16px;
          margin: 0;
        }
      }
    }
  }
  .boxbtm {
    .uesrdata {
      display: flex;
      width: 320px;
      justify-content: space-between;
      margin-top: 28px;
      li{
        text-align: center;
        transform: scale(0.95);
      }
    }
  }
  .uesrdata {
    .num {
      font-weight: bold;
    }
    .numname {
      margin-top: 8px;
      font-size: 14px;
      color: #838385;
    }
  }
  
    .contentnav {
    height: 60px;
    box-shadow: 0 0 3px #ccc;
    .navbox {
      height: 60px;
      display: flex;
      align-items: center;
      .title {
        display: flex;
        align-items: center;
        justify-self: center;
        margin-right: 48px;
      }
      .iconbox {
        display: flex;
        .iconlit {
          display: flex;
          margin-right: 32px;
        }
        .icon {
          width: 24px;
          height: 24px;
        }
      }
    
  }
  .navbox {
    span {
      font-size: 17px;
      margin-left: 8px;
    }
  }
  .warp1 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    .all{
        cursor: pointer;
        height: 60px;
        position: relative;
        display: flex;
        align-items: center;
        &:hover .box{
            display: block;
        }
        .icon{
            width: 16px;
            height: 16px;
            margin-left: 10px;
        }  
        .box{
            display: none;
            .choice{
            
            position: absolute;
            top: 60px;
            left: -12px;
            display: flex;
            flex-direction: column;
            align-items: center;
            z-index: 10;
            background-color: #fff;
            width: 100px;
            // height: 100px;
            border-radius: 5px;
            box-shadow: 0 0 5px #ccc;
            .con{
                font-weight: bold;
            }
            div{
                width: 100px;
                padding: 10px 0;
                text-align: center;
                &:hover{
                    background-color: #eee;
                }
            }
        } 
        }
        
    }
  }
  }
  .follow{
    padding-top: 20px;
    background-color: #f7f8f9;
    padding-bottom: 15px;
    .boxmain{
        display: flex;
        flex-wrap: wrap;
    }
    .box{
        &:nth-child(3n){
            margin-right: 0;
        }
        margin-right: 12px;
        display: flex;
        justify-content: center;
        width: 392px;
        box-sizing: border-box;
        border-radius: 5px;
        background-color: #fff;
        box-shadow: 0 0 2px #ccc;
        padding: 24px;
        margin-bottom: 10px;
        .userimg{
            margin: 0 auto;
            box-shadow: 0 0 5px #ccc;
            width: 84px;
            height: 84px;
            border-radius: 50%;
            overflow: hidden;
            cursor: pointer;
        }
        .userinfo{
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 28px;
            margin-top: 5px;
            margin-bottom: -8px;
            .name{
                font-weight: bold;
                font-size: 14px;
                margin-right: 8px;

            }
            .icon{
                width: 15px;
                height: 15px;
                margin-right: 8px;
            }
        }
        .boxbtm{
            margin-top: 20px;
            .uesrdata{
                li{
                    .num{
                        font-size: 16px;
                        font-weight: normal;
                    }
                    .numname{
                        font-size: 12px;
                    }
                }
            }
        }
      
        .btn{
            cursor: pointer;
            margin: 0 auto;
            background-color: #f7f7f7;
            border-radius: 5px;
            line-height: 32px;
            width: 24px;
            height: 32px;
            margin-top: 24px;
            padding: 0 17px;
            font-size: 12px;
            font-weight: bold;
            color: #1088f2;
        }
        .con{
            width: 36px;
            background: #1088f2;
            color: #fff;

        }
    }
  }
  /* 瀑布流布局 */
  .main {
    // .nullbox{
    //     height: 50px;
    // }
    padding-top: 20px;
    background-color: #f7f8f9;
    padding-bottom: 15px;
    .mainbox{
        
        display: flex;
        flex-flow: column wrap;
        align-content: space-between;
        height: 130vh;
        &::before,
        &::after{
            content: "";
            flex-basis: 100%;
            width: 0;
            order: 2;
        }
       
    }
    .box {
    //   column-gap: 20px;
    //   column-count: 3;
    width: 32%;
    &:nth-child(3n+1){order: 1}
    &:nth-child(3n+2){order: 2}
    &:nth-child(3n){order: 3}
      .content {
        .imgbox {
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
    .content {
      position: relative;
      overflow: hidden;
      margin-bottom: 16px;
      &:hover {
        .boxmain {
            transition: all 0.2s linear;
            opacity: 1;
        }
      }
      .boxmain{
        opacity: 0;
        .user {
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        background-image: linear-gradient(-180deg, transparent 0%, rgba(0, 0, 0, 0.6) 97%);
        padding: 16px;
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        position: absolute;
        bottom: 4px;
        // left: -387px;
        left: 0;
        p {
          font-size: 14px;
          font-weight: bold;
          color: #fff;
          margin-bottom: 10px;
        }
        .usermain {
          p {
            margin-bottom: 0;
          }
        }
      }
      }
      
    }
    .usermain {
      display: flex;
      justify-content: space-between;
      .headimg {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        overflow: hidden;
      }
      .useimg {
        display: flex;
        align-items: center;
      }
      .state {
        display: flex;
        align-items: center;
        .icon {
          width: 16px;
          height: 16px;
          margin-right: 5px;
          margin-left: 10px;
          margin-top: -3px;
        }
      }
    }
  }

}
</style>